﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using motelmanagement.common;
using System.Data;
using System.Data.OleDb;
namespace motelmanagement.dao
{
    class LevelDAO
    {
        SqlUtil sqlUtil = new SqlUtil();
        private string strSql = null;
        OleDbCommand cmd = null;
        public DataTable getAllLevel() {
            cmd = new OleDbCommand("SELECT Level.level_id, Level.level_name FROM [Level]");
            sqlUtil.Load(cmd);
            return sqlUtil;
        }
        public DataTable getLevel(int levelID)
        {
            cmd = new OleDbCommand("SELECT Level.level_id, Level.level_name FROM [Level] Where level_id=@id");
            cmd.Parameters.Add("id",SqlDbType.Int).Value=levelID;
            sqlUtil.Load(cmd);
            return sqlUtil;
        }
        public void insertLevel(string levelName) {
            cmd = new OleDbCommand("Insert Into [Level](level_name) Values(@name)");
            cmd.Parameters.Add("name", SqlDbType.NText).Value = levelName;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
        public void updateLevel(int levelID,string levelName)
        {
            cmd = new OleDbCommand("Update [Level] Set level_name=@name Where level_id=@id");
            cmd.Parameters.Add("name", SqlDbType.NText).Value = levelName;
            cmd.Parameters.Add("id", SqlDbType.Int).Value = levelID;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
        public void deleteLevel(int levelID)
        {
            cmd = new OleDbCommand("Delete From Level Where level_id=@id");
            cmd.Parameters.Add("id", SqlDbType.Int).Value = levelID;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
    }
}
